package com.htjc.integral.account.util;

import java.util.HashMap;
import java.util.Map;

import com.htjc.utils.check.StringUtil;
import com.htjc.utils.http.HttpUtils;

import lombok.extern.slf4j.Slf4j;

@Slf4j(topic = "jfLog")
public class DebAsetHttpUtil { 
//	public static String URL_BEFOR="http://192.168.70.72:8082/";
	
	public static String sendPost(String url,Map<String,String> header,Map<String,String> data,String logMsg){
		log.info(logMsg+"【资产中心】URL："+url);
		String  str="";
		Map<String,String> params= new HashMap<String, String>();
		StringBuffer headerStr= new StringBuffer();
		StringBuffer dataStr= new StringBuffer();
		if(header!=null){
			int i=0; 
			int j=header.entrySet().size();
			for(Map.Entry<String, String> pa:header.entrySet()){ 
				headerStr.append(pa.getKey()+":'"+pa.getValue()+"'"); 
				if(i<j-1){
					headerStr.append(",");
				}
				i++;
			};
		}
		if(data!=null){
			int i=0; 
			int j=data.entrySet().size();
			for(Map.Entry<String, String> pa:data.entrySet()){ 
				dataStr.append(pa.getKey()+":'"+pa.getValue()+"'"); 
				if(i<j-1){
					dataStr.append(",");
				}
				i++;
			};
		}
//		params.put("data", "{header:{PLAT:'1',"+headerStr.toString()+"},data:{"+dataStr.toString()+"}}");
		params.put("data", "{header:{"+headerStr.toString()+"},data:{"+dataStr.toString()+"}}");
		log.info(logMsg+"【资产中心】请求参数："+params);
		try {
			str=HttpUtils.URLPost(url, params);
			log.info(logMsg+"【资产中心】返回参数："+str);
		} catch (Exception e) {
			log.error(logMsg+"【资产中心】调用异常"+e.getMessage());
		}
		return str;
	}
	
	public static String tokenPost(String url,Map<String,String> param,String sessionId){
		String  str="";
		Map<String,String> params= new HashMap<String, String>();
		StringBuffer sbf= new StringBuffer();
		String loginData="";
		if(!StringUtil.isEmpty(sessionId)){
			loginData=",TOKEN:'"+sessionId+"'";
			sbf.append("TOKEN:'"+sessionId+"',");
		}
		if(param!=null){
			int i=0; 
			int j=param.entrySet().size();
			for(Map.Entry<String, String> pa:param.entrySet()){ 
				sbf.append(pa.getKey()+":'"+pa.getValue()+"'"); 
				if(i<j-1){
					sbf.append(",");
				} 
				i++;
			};
		}
		params.put("data", "{header:{PLAT:'1'"+loginData+",CHANNEL_RESOURCE:'5'},data:{"+sbf.toString()+"}}");
		System.out.println("{header:{PLAT:'1'"+loginData+"},data:{"+sbf.toString()+"}}");
		try {
			 str=HttpUtils.URLPost(url, params);
			System.out.println(str);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return str;
		
	}
	
	public static String post(String url,Map<String,String> param,String sessionId){
		String  str="";
		Map<String,String> params= new HashMap<String, String>();
		StringBuffer sbf= new StringBuffer();
		String loginData="";
		if(!StringUtil.isEmpty(sessionId)){
			loginData=",SESSIONID:'"+sessionId+"'";
			sbf.append("SESSIONID:'"+sessionId+"',");
		}
		loginData=",IP:'192.168.40.250',CHANNEL_RESOURCE:'5'";
		if(param!=null){
			int i=0; 
			int j=param.entrySet().size();
			for(Map.Entry<String, String> pa:param.entrySet()){ 
				sbf.append(pa.getKey()+":'"+pa.getValue()+"'"); 
				if(i<j-1){
					sbf.append(",");
				} 
				i++;
			};
		}
		params.put("data", "{header:{PLAT:'1'"+loginData+"},data:{"+sbf.toString()+"}}");
		System.out.println(params);
		try {
			 str=HttpUtils.URLPost(url, params);
			System.out.println(str);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return str;
		
	}
	
	public static String post(String url,Map<String,String> param){
		String  str="";
		Map<String,String> params= new HashMap<String, String>();
		StringBuffer sbf= new StringBuffer();
		String loginData="";
	 
		if(param!=null){
			int i=0; 
			int j=param.entrySet().size();
			for(Map.Entry<String, String> pa:param.entrySet()){ 
				sbf.append(pa.getKey()+":'"+pa.getValue()+"'"); 
				if(i<j-1){
					sbf.append(",");
				} 
				i++;
			};
		}
		params.put("data", "{header:{PLAT:'1'"+loginData+"},data:{"+sbf.toString()+"}}");
		try {
			 str=HttpUtils.URLPost(url, params);
			System.out.println(str);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return str;
		
	}
	
	public static String postOther(String url,Map<String,String> param,String sessionId){
		String  str="";
		Map<String,String> params= new HashMap<String, String>();
		StringBuffer sbf= new StringBuffer();
		String loginData="";
		if(!StringUtil.isEmpty(sessionId)){
			loginData=",SESSIONID:'"+sessionId+"'";
			sbf.append("SESSIONID:'"+sessionId+"',");
		}
		if(param!=null){
			int i=0; 
			int j=param.entrySet().size();
			for(Map.Entry<String, String> pa:param.entrySet()){ 
				sbf.append(pa.getKey()+":'"+pa.getValue()+"'"); 
				if(i<j-1){
					sbf.append(",");
				} 
				i++;
			};
		}
		params.put("data", "{header:{PLAT:'1'"+loginData+"},data:{"+sbf.toString()+"}}");
		try {
			 str=HttpUtils.URLPost(url, params);
			System.out.println(str);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return str;
		
	}

}
